<template>
	<view>
		<zmm-watermark :watermark="userStore.watermark" v-if="userStore.watermark"></zmm-watermark>
		<view class="content detail">
			<!--供应商信息-->
			<view class="detail-item">
				<uni-section title="供应商信息" type="line"></uni-section>
				<view class="detail-content">
					<view class="detail-text">
						供应商编码：
						<text>{{info.code}}</text>
						<text class="detail-text-copy" @click.stop="copyText(info.code)">复制</text>
					</view>
					<view class="detail-text">
						供应商名称：
						<text>{{info.name}}</text>
						<text class="detail-text-copy" @click.stop="copyText(info.name)">复制</text>
					</view>
					<view class="detail-text">
						联系人：
						<text>{{info.contacts}}</text>
						<text class="detail-text-copy" @click.stop="copyText(info.contacts)">复制</text>
					</view>
					<view class="detail-text">
						联系人电话：
						<text>{{info.phone}}</text>
						<text class="detail-text-copy" @click.stop="copyText(info.phone)">复制</text>
					</view>
					<view class="detail-text">
						联系人地址：
						<text>{{info.addr}}</text>
						<text class="detail-text-copy" @click.stop="copyText(info.addr)">复制</text>
					</view>
					<view class="detail-text">
						系统用户：
						<text>{{info.userName}}</text>
					</view>
					<view class="detail-text">状态：<uni-tag size="small" :type="info.status === 0 ? 'success' : ''" :text="info.status === 0 ? '正常' : '停用'" /></view>
				</view>
			</view>
			<!--收款人信息-->
			<view class="detail-item">
				<uni-section title="收款人信息" type="line"></uni-section>
				<view class="detail-content">
					<view class="detail-text">
						收款人：
						<text>{{info.receiveName}}</text>
						<text class="detail-text-copy" @click.stop="copyText(info.receiveName)">复制</text>
					</view>
					<view class="detail-text">
						收款银行：
						<text>{{info.receiveBank}}</text>
						<text class="detail-text-copy" @click.stop="copyText(info.receiveBank)">复制</text>
					</view>
					<view class="detail-text">
						收款卡号：
						<text>{{info.receiveCardNumber}}</text>
						<text class="detail-text-copy" @click.stop="copyText(info.receiveCardNumber)">复制</text>
					</view>
					<view class="detail-text">
						收款联系：
						<text>{{info.receiveContacts}}</text>
						<text class="detail-text-copy" @click.stop="copyText(info.receiveContacts)">复制</text>
					</view>
					<view class="detail-text">
						联系手机：
						<text>{{info.receiveContactsPhone}}</text>
						<text class="detail-text-copy" @click.stop="copyText(info.receiveContactsPhone)">复制</text>
					</view>
				</view>
			</view>
			
			<!-- <view class="detail-item">
				<uni-section title="商品清单" type="line"></uni-section>
				<view class="detail-content">
				</view>
			</view> -->
			
			<view class="submit" v-if="checkPermi(['zhouyz:supplierProduct:list'])">
				<button type="primary" class="submit-item" @click="submit">查看商品</button>
			</view>
			
		</view>
	</view>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app';
import { computed, onMounted, ref } from 'vue';
import { tab, auth, modal } from "@/plugins"
import { getTitle } from "@/utils/getter"
import { checkPermi, checkRole, checkOnlyPermi, checkOnlyRole } from "@/utils/permission"
import { supplierDetail, supplierProduct } from "@/api/erp_api/purchase"
import { getUserSupplier } from "@/api/system/user"
import { copyText, arrText } from '@/utils/ty.js';
import useUserStore from '@/store/modules/user'

	const userStore = useUserStore()
	onLoad(async (option) => {
		if (option.id) {
			await getAllSupplier()
			id.value = option.id
			getDetail()
		}
	})
	
	// 平台供应商用户
	const allSupplierList = ref([])
	const getAllSupplier = () => {
		return getUserSupplier().then(res => {
			allSupplierList.value = res.data.map(item => {
				return {
					...item,
					value: item.userId,
					text: `${item.nickName}`
				}
			}).filter(item => item.parentId) || []
		})
	}
	
	// 数据查询
	const id = ref('')
	const info = ref({})
	const isLoading = ref(false)
	
	const getDetail = () => {
		const params = {
			id: id.value
		}
		isLoading.value = true
		uni.showLoading({
			title: '数据加载中...'
		})
		supplierDetail(params).then(res => {
			info.value = res.data || {}
			isLoading.value = false
			uni.hideLoading()
			// searchFirst()
    }).catch(() => {
			isLoading.value = false
			uni.hideLoading()
		})
	}
	
	const submit = () => {
		uni.navigateTo({
			url:`/pages/purchase/supplierProduct?supplierId=${id.value}`
		})
	}
	
	// 数据查询
	const pageNum = ref(1)
	const pageSize = ref(10)
	const total = ref(0)
	const tableList = ref([])
	
	// 表格头部
	const columns = ref([
		{ title: '供应商信息', key: 'supplier' },
		{ title: '商品信息', key: 'goods' },
		{ title: '其他信息', key: 'other' }
	])
	
	// 从第一页查询
	const searchFirst = () => {
		pageNum.value = 1
		tableList.value = []
		getList()
	}
	//页数切换
	const pageChange = (page) => {
		pageNum.value = page
		getList()
	}
	//每页条数切换
	const sizeChange = (size) => {
		pageSize.value = size
		getList()
	}
	
	const getList = () => {
		const params = {
			pageNum: pageNum.value,
			pageSize: pageSize.value,
			supplierId: id.value
		}
		isLoading.value = true
		uni.showLoading({
			title: '数据加载中...'
		})
		supplierProduct(params).then(res => {
			tableList.value = res.rows || []
			total.value = res.total
			isLoading.value = false
			uni.hideLoading()
	  }).catch(() => {
			isLoading.value = false
			uni.hideLoading()
		})
	}
	
</script>

<style scoped lang="scss">
.submit {
	padding: 40rpx;
	&-item {
		height: 96rpx;
	}
}
</style>
